package buscopiniones;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class Configuracion {

	public static final String dirOpiniones;
	public static final String dirFreeling;
	public static final String dirPython;
	public static final String dirProlog;
	public static final String dirTrabajo;

	static {
		String sistemaOperativo = System.getProperty("os.name");
		boolean isWin = sistemaOperativo.startsWith("Win");
		String archConfig;
		if (!isWin) {
			URL input = Thread.currentThread().getContextClassLoader().getResource("configLinux.xml");
			archConfig = input.getPath();
		} else {
			URL input = Thread.currentThread().getContextClassLoader().getResource("config.xml");
			archConfig = input.getPath();
		}
		File fXmlFile;
		fXmlFile = new File(archConfig);
		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder dBuilder = null;
		try {
			dBuilder = dbFactory.newDocumentBuilder();
		} catch (ParserConfigurationException ex) {
			Logger.getLogger(Configuracion.class.getName()).log(Level.SEVERE, null, ex);
		}
		Document doc = null;
		try {
			doc = dBuilder.parse(fXmlFile);
		} catch (SAXException ex) {
			Logger.getLogger(Configuracion.class.getName()).log(Level.SEVERE, null, ex);
		} catch (IOException ex) {
			Logger.getLogger(Configuracion.class.getName()).log(Level.SEVERE, null, ex);
		}
		doc.getDocumentElement().normalize();
		dirOpiniones = doc.getDocumentElement().getElementsByTagName("dirOpiniones").item(0).getTextContent();
		dirFreeling = doc.getDocumentElement().getElementsByTagName("dirFreeling").item(0).getTextContent();
		dirPython = doc.getDocumentElement().getElementsByTagName("dirPython").item(0).getTextContent();
		dirProlog = doc.getDocumentElement().getElementsByTagName("dirProlog").item(0).getTextContent();
		dirTrabajo = doc.getDocumentElement().getElementsByTagName("dirTrabajo").item(0).getTextContent();
	}
}
